package edu.nf.ch08.mapper;

import edu.nf.ch08.entity.User;
import org.apache.ibatis.annotations.*;

/**
 * @author CSY
 * @date 2025 - 04 - 25
 */
public interface UserMapper {
    @Insert("insert into stu_info(s_name,s_age) values(#{name},#{age})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    void add(User user);

    @Update("update stu_info set s_name=#{name},s_age=#{age} where s_id = #{id}")
    void update(User user);

    @Delete("delete from stu_info where s_id = #{id}")
    void delete(int id);

    @Select("select s_id as id,s_name as name,s_age as age from stu_info where s_id = #{id}")
    //@ResultMap|@ResultType二选一
    //使用@ResultMap时，value的值是namespace + resultMap的id
    @ResultMap("edu.nf.ch08.mapper.UserMapper.userMap")
//    @ResultType(User.class)
    User getUserById(int id);
}
